<?php

class Ofx_Extjs {
	/**
	 * Ghep thong tin lap trinh controller vao layout
	 * @param $c
	 */
	
	public static function onReady($layout){

		$js=null;
				
		foreach($layout->output as $stm) $js .= PhpExt_Javascript::output($stm)."\n";		
		
		$viewport = $layout->viewport;
		$js .= PhpExt_Javascript::output($viewport->getJavascript(false, "viewport"))."\n";		
		$js .= PhpExt_Javascript::output($viewport->render("viewport"))."\n";
				
		return $js;
	}
	
	
	/**
	 * 
	 * @param $tb
	 * @param $moduleName
	 * @param $controllerName
	 * @param $actionName
	 * get function toolbar theo thanh vien
	 */
	public static function getToolbar($tb,$moduleName,$controllerName=NULL,$actionName=NULL)
	{	
		$controllerName = ($controllerName==NULL)? "index": $controllerName;
		$actionName = ($actionName==NULL)? "index": $actionName;
		
		$privilege = Ofx_Permit::getPrivilege();
		
		if(!$privilege) return;
		
		foreach ($privilege as $key=>$value)
			if($value["module_name"]==$moduleName & $value["controller_name"]==$controllerName & $value["action_name"]==$actionName){
				$actionClick="try{".$value["function_name"]."}catch(err){}";
				$tb->addButton($value["name"],$value["display_name"],OFX_ICONS.'/'.$value["icon"],new PhpExt_Handler(PhpExt_Javascript::inlineStm($actionClick)));
			}				
	}
}
